/*
 * @lc app=leetcode.cn id=714 lang=golang
 *
 * [714] 买卖股票的最佳时机含手续费
 */
package Solutions

// @lc code=start
func maxProfit(prices []int, fee int) int {
	var dp = [2]int{0, -prices[0]}
	var max = func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	for i := 1; i < len(prices); i++ {
		t := dp[0]
		dp[0] = max(dp[0], dp[1]+prices[i]-fee)
		dp[1] = max(dp[1], t-prices[i])
	}

	return dp[0]

}

// @lc code=end
